<div class="bjui-pageContent">
    <form id="user-edit" method="post" class="form-horizontal" action="/user/edit">
        <input type="hidden"  class="input-nm" name="id" id="user-id" value="{{id}}" >
        <div class="form-group">
            <label class="col-lg-12 col-sm-12 control-label "><span class="required-span">*</span>登录账号:
              
            </label>
            <div class="col-lg-12 col-sm-12 ">
                <input type="text" class="form-control input-nm" value="{{'data[account]'}}" id="user-account" name="account">
            </div>
        </div>
        
        <div class="form-group">
            <label class="col-lg-12 col-sm-12 control-label"><span class="required-span">*</span>用户名称:
              
            </label>
            <div class="col-lg-12 col-sm-12">
                <input type="text" class="form-control input-nm" value="{{'data[uname]'}}" id="user-uname" name="uname">
            </div>
        </div>
        
        <div class="form-group">
            <label class="col-lg-12 col-sm-12 control-label">登录密码:
            </label>
            <div class="col-lg-12 col-sm-12">
                <div class="input-group">
                    <span class="input-group-addon">
                        <i class="fa fa-lock" aria-hidden="true"></i>
                    </span>
                    <input type="password" class="form-control input-nm" readonly="true" value="12345678" >
                    <input type="hidden" id="user-pwd" name="pwd" value="12345678">
                </div>
                {{#if id}}
                 <button type="button" class="field-save-btn mt-4" style="margin-left:0px" onclick="reset_pwd()">重置密码</button>
                {{/if}}
            </div>
        </div>
         <div class="form-group">
            <label class="col-lg-12 col-sm-12 control-label"><span class="required-span">*</span>所属角色:</label>
            <div class="col-lg-12 col-sm-12">
               <select class="selectpicker show-tick form-control input-nm" name="roid" id="user-roid">
                   <option value="" disabled selected  style = 'display：none;' >请选择角色</option>
               </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg-12 col-sm-12 control-label">联系电话:
            </label>
            <div class="col-lg-12 col-sm-12">
                <input type="text" class="form-control input-nm" value="{{'data[tel]'}}" name="tel" id="user-tel">
            </div>
        </div>

       <div class="form-group">
            <label class="col-lg-12 col-sm-12 control-label">电子邮件:
            </label>
            <div class="col-lg-12 col-sm-12">
                <input type="text" class="form-control input-nm" value="{{'data[email]'}}" name="email" id="user-email">
            </div>
        </div>

        

        <div class="form-group">
            <label class="col-lg-12 col-sm-12 control-label">用户描述:</label>
            <div class="col-lg-12 col-sm-12">
           <textarea style="height: 100px" name="memo" value="{{'data[memo]'}}" id="user-memo"></textarea>
            </div>
        </div>
    </form>
</div>
<div class="btns-group bjui-pageFooter">
    <button type="button" class="close-btn">取消</button>
    <button type="submit" class="save-btn">保存</button>
</div>
<script type="text/javascript">
     
     $(function() {        
       $('.selectpicker').selectpicker();//初始化
        get_select_list('{{id}}');
        
          dialog_close(); //写于public.js
         

        $('#user-edit').find('[name="roid"]') .selectpicker() .change(function(e) { /* Revalidate the language when it is changed */ 
            $('#user-edit').formValidation('revalidateField', 'roid'); 
          }) .end().formValidation({       
            framework: 'bootstrap', 
            excluded: ':disabled',
            trigger:'blur', 
            icon: { valid: 'glyphicon glyphicon-ok', 
            invalid: 'glyphicon glyphicon-remove', 
            validating: 'glyphicon glyphicon-refresh' }, 
            fields: {                                 
                account: {                            //字段
                    validators: {                     //验证器
                        notEmpty: {
                            message: '请填写登录账号'
                        },
                        regexp: {
                            regexp: /^[a-zA-Z0-9_-]{6,30}$/,
                            message: '账号只能由字母、数字、下划线和减号组成,长度必须大于6,小于30个字符'
                        }
                    }
                },
                uname: {
                    validators: {
                        notEmpty: {
                            message: '请填写用户名称'
                        },
                        regexp: {
                            regexp: /^[\u4e00-\u9fa5_a-zA-Z0-9-]{2,30}$/,
                            message: '用户名只能由字母、数字、中文、下划线和减号组成,长度必须2到30之间'
                        }
                    }
                    
                },
                pwd: {
                   validators: {
                        notEmpty: {
                              message: '请填写密码'
                        }
                    }
                },
               tel:{
                  validators: {
                      regexp: {
                            regexp: /(^0?(13[0-9]|15[012356789]|17[013678]|18[0-9]|14[57])[0-9]{8}$)|(^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$)/,
                            message: '请重新填写电话'
                      }
                  }
               },
               email:{
                validators:{
                    emailAddress:{
                        message:'请重新填写邮箱地址'
                    }
                 }
               },
               roid:{
                validators:{
                    notEmpty:{
                        message:'请选择角色'
                    }
                 }
               },
               memo:{
                  validators: {
                      stringLength:{
                        message:'用户描述不得超过200个字符',
                        max:200
                      }
                  }
              }
            }
        })
         .on('success.form.fv', function(e) {
        e.preventDefault();
        var $form = $(e.target);
        var bv = $form.data('formValidation');
        $.post($form.attr('action'), $form.serialize(), function(result) {
            if(result.statusCode=='200'){
                BJUI.alertmsg('ok',result.message);
                BJUI.dialog('closeCurrent');
                BJUI.navtab('refresh', 'sysuser');
            }else{
              BJUI.alertmsg('error',result.message);
            }
        }, 'json');
     });
  });

     function reset_pwd(){
        $('#user-pwd').val('12345678');
        BJUI.alertmsg('ok','重置密码成功!');
     }
    function getAppInfo(ids){          //获取下拉框初始值
       $('.selectpicker').selectpicker();
        BJUI.ajax('doajax',{
          url:"/user/getUser",
          type:"post",
          okalert:false,
          dataType:"json",
          data:{"id":ids},
          okCallback:function(data){  //id发送成功向页面发送信息 
            $("#user-account").val(data.data.account);
            $("#user-uname").val(data.data.uname);
            $("#user-pwd").val(data.data.pwd);
            $("#user-tel").val(data.data.tel);
            $("#user-email").val(data.data.email);
            $("#user-roid").val(data.data.roid);
            $('#user-roid').selectpicker('render');
            $("#user-memo").val(data.data.memo);
          }
      });
   }      

     function get_select_list(id){
        $.ajax({
            url:"/user/getRoleList",
            type:"post",
            data:{'id':id},
            dataType:"json",
            success:function(data){
                if(data.statusCode=='200' && data.list !=''){
                    $.each(data.list,function(i,item){
                      if(item.id==2){
                        $("#user-roid").append('<option value="'+item.id+'" >'+item.name+'</option>')
                      }else{
                        $("#user-roid").append('<option value="'+item.id+'" >'+item.name+'</option>')
                      }
                    })
                }
                $("#user-roid").selectpicker('render');
                $("#user-roid").selectpicker('refresh');
                if (id) {
                    getAppInfo(id);
                }
            }
         })

       }
   
    </script>
